package com.example.alarmservice;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TimePicker;

import java.text.MessageFormat;
import java.util.Calendar;

public class MainActivity extends Activity implements TimePicker.OnTimeChangedListener {

    public static final String ACTION_ALARM = "com.book.action.set_alarm";
    private AlarmManager am = null;
    private TimePicker tpTime;
    private  int hourOFDAY=0;
    private int minute=0;
    String text;
    private Calendar calendar =Calendar.getInstance();
    PendingIntent sender;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tpTime = (TimePicker) super.findViewById(R.id.tp_time);
        tpTime.setIs24HourView(true);
        tpTime.setOnTimeChangedListener(this);
        Intent i=new Intent(MainActivity.this,AlarmRecevice.class);
        i.setAction(ACTION_ALARM);
        sender=PendingIntent.getBroadcast(MainActivity.this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
    }

    public void clickSet(View v){
        am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),sender);
        Object[]args={hourOFDAY,minute};
        if (hourOFDAY<10){
            args[0]="0"+hourOFDAY;
        }
        if (minute<10){
            args[1]="0"+minute;
            text= MessageFormat.format("");

        }
    }

    @Override
    public void onTimeChanged(TimePicker timePicker, int i, int i1) {

    }
}
